# 身份证号提取信息
import datetime

from openpyxl import load_workbook


def create_time():
    wb = load_workbook('../02.py_excelFile/persion.xlsx')
    sh = wb.active
    max_column = sh.max_column
    for i, cell in enumerate(sh['B']):
        pno = cell.value  # 6位行政区划，4位年，2位月，2位日，4位个人识别码
        year = pno[6:10]
        month = pno[10:12]
        day = pno[12:14]

        now_year = datetime.datetime.today().year
        age = int(now_year) - int(year)
        print(f'{pno} -- {year}年{month}月{day}日 -- 年龄：{age}')

        sh.cell(i + 1, max_column + 1).value = year
        sh.cell(i + 1, max_column + 2).value = month
        sh.cell(i + 1, max_column + 3).value = day
        sh.cell(i + 1, max_column + 4).value = age

    wb.save('../02.py_excelFile/15.身份证号信息修改.xlsx')


if __name__ == '__main__':
    create_time()
